package ch.bfh.fbi.mobicomp.zap10;

import java.math.BigInteger;

import ch.simplix.android.digest.DigestHelper;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class Zap10MessageBroadcastReceiver extends BroadcastReceiver {
	private static final String TAG = "Zap10MessageBroadcastReceiver";
	private static final BigInteger destructionKey = new BigInteger(
			"9d28ec8a787bd9be46bb26863e6e770a4e5f57f3", 16);
	private static final BigInteger haltKey = new BigInteger(
			"da2d54cee2f6944883dcb5ccb2971173ff512a3a", 16);

	
	@Override
	public void onReceive(Context context, Intent intent) {
		Intent zapperIntent = new Intent(
				"ch.bfh.fbi.mobicomp.zap10.ZAP_10_SERVICE");
		if(DigestHelper.isEqual(intent.getExtras().getString("message"), destructionKey)) {
			Log.d(TAG, "destruction initiated...");
			zapperIntent.putExtra("start",true);			
		}else if(DigestHelper.isEqual(intent.getExtras().getString("message"), haltKey)) {
			Log.d(TAG, "destruction aborted...");
			zapperIntent.putExtra("stop",true);
		}			
		context.startService(zapperIntent);		
	}

}
